<template>
  <div class="dataBox" :class="{ border: isBorder }">
    <div class="dataBox-icon" v-if="isIcon" :style="{ backgroundColor: backgroundColor }">
      <component :is="icon" /> <!-- 使用图标组件 -->
    </div>
    <div class="dataBox-des">
      <div class="dataBox-des-text">{{ text }}</div>
      <div class="dataBox-des-value">{{ value }}</div>
    </div>
  </div>
</template>

<script lang="ts">
import type { DefineComponent, PropType } from 'vue';

export default {
  name: "DataBox",
  props: {
    isIcon: {
      type: Boolean,
      default: true,
    },
    isBorder: {
      type: Boolean,
      default: true,
    },
    icon: {
      type: [String, Object] as PropType<string | object>, // 类型注解为 String 或 Object
      default: null,
    },
    backgroundColor: {
      type: String,
      default: "",
    },
    text: {
      type: String,
      default: "",
    },
    value: {
      type: [Number, String] as PropType<number | string>,
      default: "",
    },
  },
} as DefineComponent<{

  icon: string | object | null;
  backgroundColor: string;
  text: string;
  value: string | number;
}>;
</script>

<style lang="scss" scoped>
.dataBox {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding: 10px;
  justify-content: flex-start;
  border-radius: 10px;
  &-icon {
    color: #fff;
    width: 6vh;
    height: 6vh;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 5px;
    margin-right: 5px;
  }
  &-des {
    &-text {
      font-weight: 400;
      color: var(--text-color);
      font-size: 0.6rem;
    }
    &-value {
      font-size: 1.2rem;
      margin-top: 2px;
      text-align: center;
    }
  }
}
.border {
  border: var(--border-color) 1px solid;
}
</style>
